package vg.services.user_interface_manager.additional_swing_components.conditionPanel.components;

import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.util.Map;
import java.util.Set;

import javax.swing.JComponent;
import javax.swing.JPanel;


public class ConditionWrapper {
	// Defines
	public static final int DEF_EMPTY_CONDITION = -1;
	public static final int DEF_GENERAL_CONDITION = 0;
	public static final int DEF_NUMBER_ONLY_CONDITION = 1;
	public static final int DEF_STRING_ONLY_CONDITION = 2;
	public static final String[] DEF_TYPES = {"General", "Number"};
	// Data
	private int type;
	private ICondition condition = null;
	// Swing data
	private JPanel view;
	/**
	 * Constructor.
	 */
	public ConditionWrapper() {
		view = new JPanel(new GridLayout(1, 1));
		type = DEF_EMPTY_CONDITION;
	}
	
	public void setGeneralType(Map<String, Set<String>> generalAttributes) {
		type = DEF_GENERAL_CONDITION;
		condition = new GeneralCondition(generalAttributes, DEF_TYPES);
		view.removeAll();
		view.add(condition.getView());
	}
	
	public void setNumberType(Set<String> numberAttributes) {
		type = DEF_NUMBER_ONLY_CONDITION;
		condition = new NumberCondition(numberAttributes, DEF_TYPES);
		view.removeAll();
		view.add(condition.getView());
	}
	
	public JComponent getView() {
		return view;
	}
	
	public int getType() {
		return type;
	}
	
	public ICondition getCondition() {
		return condition;
	}
	
	public void updateUITheme() {
		condition.updateUITheme();
	}
	
	public void addClosingListener(ActionListener l) {
		if(condition != null)
			condition.addClosingListener(l);		
	}
	
	public void removeClosingListener(ActionListener l) {
		if(condition != null)
			condition.removeClosingListener(l);				
	}
	
	public void addChangeTypeListener(ActionListener l) {
		if(condition != null)
			condition.addChangeTypeListener(l);
	}
	
	public void removeChangeTypeListener(ActionListener l) {
		if(condition != null)
			condition.removeChangeTypeListener(l);
	}
}
